package com.pinyougou.sellergoods.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import com.alibaba.dubbo.config.annotation.Service;
import com.pinyougou.mapper.TbItemCatMapper;
import com.pinyougou.pojo.TbItemCat;
import com.pinyougou.pojo.TbItemCatExample;
import com.pinyougou.pojo.TbItemCatExample.Criteria;
import com.pinyougou.sellergoods.service.itemCatService;
@Service
public class ItemCatServiceImpl implements itemCatService{
	@Autowired
	private TbItemCatMapper itemCat;
	@Autowired
	private RedisTemplate redis;

	@Override
	public List<TbItemCat> findByparentId(long parentId) {
		
		TbItemCatExample example=new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		
		List<TbItemCat> findAll = findAll();
		for(TbItemCat itemcat:findAll) {
			redis.boundHashOps("itemCat").put(itemcat.getName(), itemcat.getTypeId());
		}
		
		System.out.println("更新缓存,商品分类ID");
		
		return itemCat.selectByExample(example);
	}

	@Override
	public TbItemCat findOne(long id) {
		
		return itemCat.selectByPrimaryKey(id);
	}

	@Override
	public List<TbItemCat> findAll() {
	return	itemCat.selectByExample(null);
	}
}
